home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / nodee1.arc / SOURCE.ARC / NODCHILD.CPP < prev    next >
C/C++ Source or Header  |  1991-09-01  |  7KB  |  331 lines

  1. /*
  2. NODCHILD.CPP
  3.  
  4. code for child windows for the NoD program
  5.  
  6. */
  7.  
  8.     #if !defined( __WINDOWS_H )
  9.     #include <Windows.h>
  10.     #endif  // __WINDOWS_H
  11.  
  12.     #if !defined( __NODCHILD_H )
  13.     #include "Nodchild.h"
  14.     #endif
  15.  
  16.     #ifndef __NOD1_H
  17.     #include "nod1.h"
  18.     #endif
  19.  
  20.     #ifndef __STRING_H
  21.     #include <string.h>
  22.     #endif
  23.  
  24.  
  25. /*------------------------------------------------ Child Classes
  26.  
  27. */
  28.  
  29.     void DBox::create(HWND hA)
  30.     {
  31.  
  32.         HDC hdc;
  33.         TEXTMETRIC tm;
  34.         int cxChar,cyChar;
  35.         char *text="ICK!";
  36.  
  37.         hParent=hA;
  38.  
  39.         hdc=GetDC(hParent);
  40.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  41.         GetTextMetrics(hdc,&tm);
  42.         cxChar=tm.tmAveCharWidth;
  43.         cyChar=tm.tmHeight+tm.tmExternalLeading;
  44.         ReleaseDC(hParent,hdc);
  45.  
  46.         hwndChild=CreateWindow
  47.             ("button",text,WS_CHILD|WS_VISIBLE|SS_CENTER,
  48.             42*cxChar,5*cyChar,
  49.             (strlen(text)+2)*cxChar,2*7*cyChar/4,
  50.             hParent,MYCW_ICKBUTTON,WinBase::hInst,NULL);
  51.         unset();
  52.     }
  53.  
  54.     void DBox::set(void)
  55.     {
  56.         ShowWindow(hwndChild,SW_SHOWNORMAL);
  57.         EnableWindow(hwndChild,TRUE);
  58.     }
  59.  
  60.     void DBox::unset(void)
  61.     {
  62.         ShowWindow(hwndChild,SW_HIDE);
  63.         EnableWindow(hwndChild,FALSE);
  64.     }
  65.  
  66. /*-----------------------------------------------
  67. */
  68.  
  69.  
  70.     void GoButton::create(HWND hA)
  71.     {
  72.  
  73.         HDC hdc;
  74.         TEXTMETRIC tm;
  75.         int cxChar,cyChar;
  76.         text="Take It Out!";
  77.  
  78.         hParent=hA;
  79.  
  80.         hdc=GetDC(hParent);
  81.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  82.         GetTextMetrics(hdc,&tm);
  83.         cxChar=tm.tmAveCharWidth;
  84.         cyChar=tm.tmHeight+tm.tmExternalLeading;
  85.         ReleaseDC(hParent,hdc);
  86.  
  87.         hwndChild=CreateWindow
  88.             ("button",text,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
  89.             40*cxChar,10*cyChar,
  90.             (strlen(text)+2)*cxChar,7*cyChar/4,
  91.             hParent,MYCW_GOBUTTON,WinBase::hInst,NULL);
  92.     }
  93.  
  94. /*------------------------------------------------------------*/
  95.  
  96.     void FirstLine::create(HWND hA)
  97.     {
  98.         HDC hdc;
  99.         TEXTMETRIC tm;
  100.         int cxChar,cyChar;
  101.         text="nothing yet";
  102.  
  103.         hParent=hA;
  104.  
  105.         hdc=GetDC(hParent);
  106.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  107.         GetTextMetrics(hdc,&tm);
  108.         cxChar=tm.tmAveCharWidth;
  109.         cyChar=tm.tmHeight+tm.tmExternalLeading;
  110.         ReleaseDC(hParent,hdc);
  111.  
  112.         hwndChild=CreateWindow
  113.             ("static",text,WS_CHILDWINDOW|WS_VISIBLE|SS_LEFT,
  114.             10*cxChar,2*cyChar,
  115.             (60+2)*cxChar,7*cyChar/4,
  116.             hParent,MYCW_FIRSTLINE,WinBase::hInst,NULL);
  117.     }
  118.  
  119.     void FirstLine::set(char* a)
  120.     {
  121.         SetWindowText(hwndChild,(LPSTR) a);
  122.     }
  123.  
  124. /*--------------------------------------------------------------------*/
  125.  
  126.     void FileList::create(HWND hA)
  127.     {
  128.         HDC hdc;
  129.         TEXTMETRIC tm;
  130.         int cxChar,cyChar;
  131.  
  132.         hParent=hA;
  133.         if (strlen(szMask)==0)
  134.             mask("*.*");
  135.  
  136.         hdc=GetDC(hParent);
  137.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  138.         GetTextMetrics(hdc,&tm);
  139.         cxChar=tm.tmAveCharWidth;
  140.         cyChar=tm.tmHeight;
  141.         ReleaseDC(hParent,hdc);
  142.  
  143.         hwndChild=CreateWindow
  144.             ("listbox",NULL,WS_CHILDWINDOW|WS_VISIBLE|LBS_STANDARD,
  145.             2*cxChar,5*cyChar,
  146.             13*cxChar+GetSystemMetrics(SM_CXVSCROLL),15*cyChar,
  147.             hParent,MYCW_FILELIST,WinBase::hInst,NULL);
  148.  
  149.         reset();
  150.  
  151.         bValidFile=FALSE;
  152.     }
  153.  
  154.     DWORD FileList::send(WORD msg,WORD wParam,long lParam)
  155.     {
  156.         return SendMessage(hwndChild,msg,wParam,lParam);
  157.     }
  158.  
  159.     void FileList::mask(char *a)
  160.     {
  161.         strcpy(szMask,a);
  162.     }
  163.  
  164.  
  165.     BOOL FileList::fileClick(void)
  166.     {
  167.         int index;
  168.         char szBuffer[MAXPATH];
  169.         OFSTRUCT ofs;
  170.  
  171.         if (LB_ERR ==    (index= (WORD) send(LB_GETCURSEL,0,0L)) )
  172.                 return FALSE;
  173.  
  174.         send(LB_GETTEXT,index,(LONG) (char far *) szBuffer);
  175.  
  176.         if (-1 != OpenFile(szBuffer,&ofs,OF_EXIST|OF_READ))
  177.         {
  178.             bValidFile=TRUE;
  179.             getcwd(szFileName,MAXPATH);
  180.             if (szBuffer[strlen(szFileName)-1] != '\\')
  181.                 strcat(szFileName,"\\");
  182.             strcat(szFileName,szBuffer);
  183.         }
  184.  
  185.         return TRUE;
  186.     }
  187.  
  188.  
  189.     BOOL FileList::validFile(void)
  190.     {
  191.         return bValidFile;
  192.     }
  193.  
  194.     char* FileList::getFile(void)
  195.     {
  196.         return szFileName;
  197.     }
  198.  
  199.     void FileList::reset(void)
  200.     {
  201.         send(LB_RESETCONTENT,0,0L);
  202.         send(LB_DIR,0x0,(LONG)(LPSTR) szMask);
  203.     }
  204.  
  205. /*--------------------------------------------------------------------
  206. DirList code
  207. */
  208.  
  209.     void DirList::create(HWND hA)
  210.     {
  211.         HDC hdc;
  212.         TEXTMETRIC tm;
  213.         int cxChar,cyChar;
  214.  
  215.         hParent=hA;
  216.  
  217.         hdc=GetDC(hParent);
  218.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  219.         GetTextMetrics(hdc,&tm);
  220.         cxChar=tm.tmAveCharWidth;
  221.         cyChar=tm.tmHeight;
  222.         ReleaseDC(hParent,hdc);
  223.  
  224.         hwndChild=CreateWindow
  225.             ("listbox",NULL,WS_CHILDWINDOW|WS_VISIBLE|LBS_STANDARD,
  226.             17*cxChar+GetSystemMetrics(SM_CXVSCROLL),8*cyChar,
  227.             13*cxChar+GetSystemMetrics(SM_CXVSCROLL),12*cyChar,
  228.             hParent,MYCW_DIRLIST,WinBase::hInst,NULL);
  229.  
  230.         reset();
  231.  
  232.  
  233. /* since the object creates this box and keeps the handle
  234. control is not allowed outside */
  235.  
  236.         hDirField=CreateWindow
  237.             ("static"," ",WS_CHILDWINDOW|WS_VISIBLE|SS_LEFT,
  238.             17*cxChar+GetSystemMetrics(SM_CXVSCROLL),6*cyChar,
  239.             (30+2)*cxChar,7*cyChar/4,
  240.             hParent,MYCW_DIRFIELD,WinBase::hInst,NULL);
  241.  
  242.         getcwd(szDirName,MAXPATH);
  243.  
  244.         SetWindowText(hDirField,szDirName);
  245.  
  246.     }
  247.  
  248.     DWORD DirList::send(WORD msg,WORD wParam,long lParam)
  249.     {
  250.         return SendMessage(hwndChild,msg,wParam,lParam);
  251.     }
  252.  
  253.  
  254.     BOOL DirList::dirClick(void)
  255.     {
  256.         int index;
  257.  
  258.         char szBuffer[MAXPATH];
  259.  
  260.         if (LB_ERR ==    (index= (WORD) send(LB_GETCURSEL,0,0L)) )
  261.                 return FALSE;
  262.  
  263.         send(LB_GETTEXT,index,(LONG) (char far *) szBuffer);
  264.  
  265.         if (strstr(szBuffer,"[-") != 0)
  266.         {
  267.             setdisk((int) (szBuffer[2]) -  'a');
  268.         }
  269.  
  270.         else
  271.         {
  272.             szBuffer[strlen(szBuffer)-1] = '\0';
  273.             chdir(szBuffer+1);
  274.         }
  275.  
  276.         getcwd(szDirName,MAXPATH);
  277.         reset();
  278.  
  279.         SetWindowText(hDirField,szDirName);
  280.  
  281.  
  282.         return TRUE;
  283.     }
  284.  
  285.     void DirList::reset(void)
  286.     {
  287.         send(LB_RESETCONTENT,0,0L);
  288.         send(LB_DIR,0xc010,(LONG)(LPSTR) "*.*");
  289.     }
  290.  
  291. /*---------------------------------------------------------------
  292. FileFinder code
  293. -------------------------------------------------------------*/
  294.  
  295.     void FileFinder::create(HWND hParent)
  296.     {
  297.         HDC hdc;
  298.         TEXTMETRIC tm;
  299.         int cxChar,cyChar;
  300.  
  301.         hdc=GetDC(hParent);
  302.         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  303.         GetTextMetrics(hdc,&tm);
  304.         cxChar=tm.tmAveCharWidth;
  305.         cyChar=tm.tmHeight;
  306.         ReleaseDC(hParent,hdc);
  307.  
  308.         FileList::create(hParent);
  309.         DirList::create(hParent);
  310.  
  311.  
  312.     }
  313.  
  314.     void FileFinder::reset(void)
  315.     {
  316.         FileList::reset();
  317.         DirList::reset();
  318.     }
  319.  
  320.     BOOL FileFinder::dirClick()
  321.     {
  322.         BOOL i;
  323.         i=DirList::dirClick();
  324.         FileList::reset();
  325.         return i;
  326.     }
  327.  
  328.     void FileFinder::send(void)
  329.     {
  330.     }
  331.